package cn.com.guage.guc.sync;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author: LDeng
 * @Date: 2021-09-05 14:49
 */
//可重入锁, 递归锁
public class SyncLockDemo2 {

    public static void main(String[] args) {
        //lock 演示可重入锁
        Lock lock = new ReentrantLock();
        //创建线程
        new Thread(() -> {
            try {
                lock.lock();
                System.out.println(Thread.currentThread().getName() + "外层");
                try {
                    lock.lock();
                    System.out.println(Thread.currentThread().getName() + "内层");
                } finally {
                    lock.unlock();
                }

            } finally {
                lock.unlock();
            }

        }, "t1").start();

        new Thread(()->{
            lock.lock();
            System.out.println("aaaa");
            lock.unlock();
        },"aa").start();
    }


}
